<template>
    <div class="newInfo">
        <div v-for="(item,index) in NewsInfo" :key="item.id">
            <div v-if="item.id == newId">
                <h3 class="title">{{item.title}}</h3>
                <p class="subTitle">
                    <span>发表时间：{{item.add_time}}</span>
                    <span>点击：{{item.click}}次</span>
                </p>
                <hr>
                <div class="content">
                    <p style="color: red">id为{{newId}}</p>
                    <div v-html="item.content"></div>
                </div>

            </div>
        </div>
        <!--父组件给子组件传参-->
        <comment-box :id="this.newId"></comment-box>
    </div>
</template>
<script>
    import {Toast} from 'mint-ui';
    //导入评论组件
    import comment from '../subcomponents/comment.vue';
    export default{
        data(){
            return {
                newId:this.$route.params.id, //将url地址中传递过来的 id值，挂载到data上，方便以后调用
                NewsInfo:[]
            }
        },
        created(){
            this.getNewsInfo();
        },
        methods: {//获取课程详情
            getNewsInfo(){
                this.$http.get('src/mock/NewsInfo.json').then(result=>{
                    if (result.status === 200){
                        this.NewsInfo = result.body;
                    }else {
                        Toast('获取信息失败！');
                    }
                })
            }
        },
        computed: {},
        components: {
            //注册子组件节点
            "comment-box":comment
        }
    }
</script>
<style lang="scss" scoped>
.newInfo{
    padding: 0 5px;
    .title{
        font-size: 14px;
        text-align: center;
        margin: 15px 0;
        color: red;
    }
    .subTitle{
        font-size: 12px;
        color: #22abff;
        display: flex;
        justify-content: space-between;
    }
}
</style>